package com.mmall.concurrency.example.immutable;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ImmutableExample3 {

    private final static ImmutableList<Integer> list = ImmutableList.of(1,2,3);

    private final static ImmutableSet set = ImmutableSet.copyOf(list);

    private final static ImmutableMap<Integer, Integer> map = ImmutableMap.of(1,2,3,4);

    private final static ImmutableMap<Integer, Integer> map2 = ImmutableMap.<Integer,Integer>builder()
            .put(1,2).put(3,4).put(5,6).build();

    public static void main(String[] args) {
        /**
         * 以下操作都是不被允许的，编译器提示过时方法，执行会抛异常
         */
        list.add(4);
        set.add(4);
        map.put(1,4);
        map2.put(7,8);
        /**
         * Exception in thread "main" java.lang.UnsupportedOperationException
         * 	at com.google.common.collect.ImmutableCollection.add(ImmutableCollection.java:218)
         * 	at com.mmall.concurrency.example.immutable.ImmutableExample3.main(ImmutableExample3.java:19)
         */
    }
}
